//文章接口api
import { http } from '../utils'

interface ArticleDTO {
    uuid: string;
    title: string;
    content: string;
    tags: Array<string>;
    category: string;
    author: string;
    publish_status: number | string;
    right: '私有' | '公开'
}

interface UpdateArticleDto {
    title?: string;
    content?: string;
    category?: string;
    tags?: Array<string>;
    publish_status: number;
    views?: number;
    likes?: number;
}


export const addArticle = (data: ArticleDTO) => http.post('/article', data)

/* 
 *  通过条件匹配某作者的某一里文章
 * */
export const findArticles = (data?: { keyword?: string, uuid?: string, publish_status?: number, right?: string, pageSize?: number, page?: number, limit?: number, orderDto?: { sort: string, order: "ASC" | "DESC" } }) => http.get('/article', { params: data })

/* 
 *  通过文章id修改文章
 * */
export const updateArticle = (id: number, updateArticleDto: UpdateArticleDto) => http.patch(`/article/${id}`, updateArticleDto)

/* 
 * 通过文章id查找文章
 * */
export const findOneArticle = (id: number, uuid: string) => http.get(`/article/${id}`, { params: { uuid } })

/* 
 *  通过文章id删除文章
 * */
export const deleteArticle = (id: number) => http.delete(`/article/${id}`)


//查询历史记录
export const articleHistory = (data: { uuid: string, keyword?: string, page: number, pageSize: number }) => http.post('/article/articleHistory', data)

//文章添加评论
export const addArticleComment = (data: { uuid: string, articleId: number, content: string, parentId?: number }) => http.post('/article/addArticleComment', data)


//删除文章评论
export const delArticleComment = (data: { uuid: string, articleId: number, commentId: number }) => http.post('/article/delArticleComment', data)

//查询文章所有评论
export const findArticleComment = (data: { articleId: number }) => http.post(`/article/findArticleComment`, data)

//文章评论点赞
export const commentFavor = (data: { uuid: string, commentId: number, articleId: number }) => http.post('/article/commentFavor', data)


